
<template>
  <!-- 案例征集查询弹窗 -->
  <div>
    <!-- 搜索 -->
    <TopFilter :list="topFilterInit" :cols="2" labelWidth="120" @filterChange="changeHandle"></TopFilter>
    <!-- table -->
    <FilterTable
      ref="table"
      :columns="columns"
      :isSelectColumn="isSelectColumn"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'records'"
      selectionType="single"
      :height="300"
      :onRowSelectChange="onRowSelectChange"
      :onColumnsChange="columns => this.columns = columns"
      columnsRef="projectOperating_case_departmentReport_caseCollectMadal_01"      
      
    ></FilterTable>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <el-button @click="goback">取 消</el-button>
      <el-button type="primary" :loading="reqLoading" @click="req">确 定</el-button>
    </div>
  </div>
</template>

<script>
import { getCaseCollectionList, selectListByBill } from '@/api/cms-api/projectOperating/case/oemCollect/index';
import { dictionary } from '@/utils/dictMixin';
import { formatdateByDay } from '@/utils/index';
export default {
  mixins: [dictionary],
  props: {
    fatherReq: Function,
    fatherGoBack: Function
  },
  //初始化数据  全局变量
  data() {
    return {
      topFilterInit: this.topFilterInitFun(),
      columns: this.creatHeader(),
      isSelectColumn: true,
      fetchApi: getCaseCollectionList, //ipa 接口
      fetchParams: { caseLevyStatus: 25331002, isOut: 1 }, //参数
      choose: [], //选中的对象
      reqLoading: false
    };
  },
  //方法、事件
  methods: {
    //选中数据
    async onRowSelectChange(val) {
      //选中一条数据查询是否有对应附件
      this.choose = val[0];
      if (val[0] != null) {
        let fileParams = { caseLevyId: val[0].caseLevyId, billType: 25681001 };
        await selectListByBill(fileParams).then(res => {
          if (res.data.length > 0) {
            let caseUrlList = [];
            for (let j = 0; j < res.data.length; j++) {
              let o1 = { name: res.data[j].fileName };
              let o2 = { url: res.data[j].fileId };
              let a = Object.assign(o1, o2);
              caseUrlList.push(a);
            }
            // debugger;
            val[0] = Object.assign({}, { collectFile: caseUrlList }, val[0]);
          }
          this.choose = val[0];
        });
      }
    },
    //确定
    req() {
      if (this.choose == null) {
        this.$notify.warning({ title: '提示信息', message: '请选择一个案例!' });
        return;
      }
      this.reqLoading = true;
      this.fatherReq(this.choose);
    },
    //取消
    goback() {
      this.fatherGoBack();
    },
    //搜索数据
    topFilterInitFun() {
      return [
        { type: 'INPUT', label: '优秀案例征集编号', fieldName: 'caseLevyCode', initialValue: '' },
        { type: 'INPUT', label: '优秀案例征集名称', fieldName: 'caseLevyName', initialValue: '' },
        {
          type: 'RANGE_DATE',
          label: '征集开始时间',
          fieldName: 'levyStartDate',
          initialValue: ''
        },
        {
          type: 'RANGE_DATE',
          label: '征集结束时间',
          fieldName: 'levyEndDate',
          initialValue: ''
        },
        {
          type: 'RANGE_DATE',
          label: '项目开始时间',
          fieldName: 'projectExecuteStartDate',
          initialValue: ''
        },
        {
          type: 'RANGE_DATE',
          label: '项目结束时间',
          fieldName: 'projectExecuteEndDate',
          initialValue: ''
        },
        {
          type: 'RANGE_DATE',
          label: '下发时间',
          fieldName: 'lssuedStartDate',
          initialValue: ''
        }
      ];
    },
    //table表头和数据源
    creatHeader() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '优秀案例征集编号',
          dataIndex: 'caseLevyCode',
          sorter: true
        },
        { title: '优秀案例征集名称', dataIndex: 'caseLevyName', sorter: true },
        {
          title: '征集开始时间',
          dataIndex: 'levyStartDate',
          sorter: true,
          render: props => {
            return <span>{formatdateByDay(props.row.levyStartDate)} </span>;
          }
        },
        {
          title: '征集结束时间',
          dataIndex: 'levyEndDate',
          sorter: true,
          render: props => {
            return <span>{formatdateByDay(props.row.levyEndDate)} </span>;
          }
        },
        {
          title: '项目开始时间',
          dataIndex: 'projectExecuteStartDate',
          sorter: true,
          render: props => {
            return <span>{formatdateByDay(props.row.projectExecuteStartDate)} </span>;
          }
        },
        {
          title: '项目结束时间',
          dataIndex: 'projectExecuteEndDate',
          sorter: true,
          render: props => {
            return <span>{formatdateByDay(props.row.projectExecuteEndDate)} </span>;
          }
        },
        {
          title: '下发时间',
          dataIndex: 'lssuedStartDate',
          sorter: true,
          render: props => {
            return <span>{formatdateByDay(props.row.lssuedStartDate)} </span>;
          }
        }
      ];
    },
    //搜索回调
    changeHandle(data) {
      let time = data.levyStartDate;
      let lssuedTime = data.lssuedStartDate;
      //征集结束时间
      data = Object.assign({}, { levyEndstart: data.levyEndDate[0] }, data);
      data = Object.assign({}, { levyEndend: data.levyEndDate[1] }, data);
      //项目开始时间
      data = Object.assign({}, { projectExecutestart: data.projectExecuteStartDate[0] }, data);
      data = Object.assign({}, { projectExecuteend: data.projectExecuteStartDate[1] }, data);
      //项目结束时间
      data = Object.assign({}, { projectExecuteEndstart: data.projectExecuteEndDate[0] }, data);
      data = Object.assign({}, { projectExecuteEndend: data.projectExecuteEndDate[1] }, data);

      data = Object.assign({}, { timestart: time[0] }, data);
      data = Object.assign({}, { timeend: time[1] }, data);
      data = Object.assign({}, { lssuedStartTime: lssuedTime[0] }, data);
      data = Object.assign({}, { lssuedEndTime: lssuedTime[1] }, data);
      data = Object.assign({}, { caseLevyStatus: 25331002 }, data);
      data = Object.assign({}, { isOut: 1 }, data);
      // console.log(data);
      this.fetchParams = Object.assign({}, data);
    },
    formatDates: function(value) {
      // 这里的 value 就是需要过滤的数据
      if (value == null || value == '') {
        return '';
      }
      var date = new Date(value);
      var year = date.getFullYear();
      var month = date.getMonth() + 1;
      var day = date.getDate();
      return year + '-' + month + '-' + day;
    }
  }
};
</script>

<style scoped>
</style>
